package xyz.fuqufyb.aec.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import xyz.fuqufyb.aec.data.JsonResult;
import xyz.fuqufyb.aec.service.IAdminUserService;

import javax.servlet.http.HttpSession;

/**
 * @author 用户: fyb
 * @description class: LoginController
 * @date 时间: 2021/1/29 15:15
 */

@Controller
public class LoginController {

    @Autowired
    private IAdminUserService userService;

    /**
     * 登录
     * @param email
     * @param password
     * @param session
     * @return
     */
    @RequestMapping("/doLogin")
    @ResponseBody
    public JsonResult doLogin(@RequestParam("email") String email, @RequestParam("password") String password, HttpSession session){

        JsonResult jsonResult = userService.userLogin(email, password);

        session.setAttribute("user",jsonResult.get("result"));
        return jsonResult;

    }

    /**
     * 退出登录
     * @param session
     * @return
     */
    @RequestMapping("/logout")
    public String logout(HttpSession session){

        return "redirect:login.html";
    }
}
